<template>
  <div>
    <p>用户名：<input type="text" v-model="from.username"></p>
    <p>密码：<input type="text" v-model="from.password"></p>
    <p>
      <button @click="login">登录</button>
    </p>
    <br><br><br><br>
    <ul v-for="i in data">
      <li>
        {{i.name}}
        <button @click="look">查看</button>
      </li>

    </ul>

  </div>
</template>

<script>
export default {
  data() {
    return {
      from:{},
      code:'',
      data:[]
    }
  },
  methods: {
    login(){
      this.axios.get('user/',this.from)
      .then(res=>{
        alert(res.data.msg)
        this.code=res.data.code
      })
    },
    news(){
      this.axios.get('news/')
      .then(res=>{
        console.log(res)
        this.data=res.data
      })
    },
    look(){
      if (this.code==200){
        this.$router.push('https://www.http://localhost:8080/#/reg')
      }else {
        alert('您无权访问')
      }
    }
  },
  mounted() {
    this.news()
  }
}
</script>

<style scoped>

</style>